{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3490dc9a",
   "metadata": {},
   "source": [
    "---\n",
    "· 日期：2022-10-19\\week09(周三)\n",
    "\n",
    "· 课程：python\n",
    "\n",
    "· 记录人：林荣烽\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "459e72e2",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "> 1. 列表的方法\n",
    "\n",
    "> 2. while循环\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a22a2eb",
   "metadata": {},
   "source": [
    "# 1.列表的方法\n",
    "\n",
    "> 1.使用.Tab键查看列表的方法\n",
    "\n",
    "> 2.使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8743cfa4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2469648e",
   "metadata": {},
   "source": [
    "## 1.1列表的增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "60e551ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1ba57406",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2a81f16e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "44e53e4b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4b9195be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9de7e0f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(2,\"Zhichao\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e6046e16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Zhichao', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62364554",
   "metadata": {},
   "source": [
    "## 1.2 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4a761581",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2a7c100d",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.remove(\"Zhichao\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c32d3039",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "865c7065",
   "metadata": {},
   "source": [
    "* 正确的删除方法的流程\n",
    "> 1. 查询value是否存在列表当中\n",
    "> 2. 对存在的value进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "02744cdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Wang\" in names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cd25df38",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-87f5ed08eeb1>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnames\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Wang\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8739a80e",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"Wang\" in names:\n",
    "    names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4542467e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：删除系统：\n",
    "## 1.如果输入的值存在，删除； 2.如果输入的结果不存在，提示用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8b92782f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "69e88178",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要删除的内容：Lihua\n",
      "删除成功！\n",
      "['Marry', 'Jan']\n"
     ]
    }
   ],
   "source": [
    "user_input_name = input(\"请输入要删除的内容：\")\n",
    "if user_input_name in names:\n",
    "    names.remove(user_input_name)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，删除无效\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce3b0e10",
   "metadata": {},
   "source": [
    " ------\n",
    "· 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2d84ec3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 重新建立names列表数据\n",
    "names = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8c1f55bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d4623907",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b007bc3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97e41776",
   "metadata": {},
   "outputs": [],
   "source": [
    "index=-1 (默认情况) index=3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "feb3dfd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Lihua'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() # 直接使用pop（），删除最后一位。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0ab19ba9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "baf4585e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "645841b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "169c0952",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "7684f6cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入删除的索引值：2\n"
     ]
    }
   ],
   "source": [
    "pop_index = int(input(\"输入删除的索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "6e0dd0c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "删除成功！\n"
     ]
    }
   ],
   "source": [
    "if pop_index<len(names):\n",
    "    names.pop(pop_index)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的值不在index的范围内\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "eb21639a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "fd68b0e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5e037cb",
   "metadata": {},
   "source": [
    "## 1.3 列表的修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "3b158f83",
   "metadata": {},
   "outputs": [],
   "source": [
    "names[0] = \"Zhichao\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0367c9c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', 'Alex']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66d3ef39",
   "metadata": {},
   "source": [
    "## 1.4 列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "e61ff6e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "b464bcb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "4c177a5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "1ef7060f",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1 = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e64ed5f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "221a536d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "2ee4d44d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class2 = [\"李晓峰\",\"王丽\",\"刘明\"]\n",
    "names_class2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "e7573254",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1.extend(names_class2) # 注意：使用列表的方法的列表进行扩展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "0eec26ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua', '李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "482f4b66",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1.sort # 排序，一般操作数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01c16f8",
   "metadata": {},
   "source": [
    "---\n",
    "* sort（）排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "de4c6aff",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,255,260,270]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "e9cc78f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(立定跳远_男生.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "9edb145b",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "8d080d71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 255, 260, 270]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "2d68fc59",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "2580a9cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 260, 255, 250, 245, 230]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66bc5fb3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "38483406",
   "metadata": {},
   "source": [
    "# 2. while循环\n",
    "\n",
    "* while True 是循环概念中非常重要的一种方式。它可以实现for循环的指定次数，也可以在特定条件下停止。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "e6616fce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，缠缠绵绵到天涯... 0\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 1\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 2\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 3\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 4\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 5\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 6\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 7\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 8\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 9\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 10\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 11\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 12\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 13\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 14\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 15\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 16\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 17\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 18\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 19\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 20\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 21\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 22\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 23\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 24\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 25\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 26\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 27\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 28\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 29\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 30\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 31\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 32\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 33\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 34\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 35\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 36\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 37\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 38\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 39\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 40\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 41\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 42\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 43\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 44\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 45\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 46\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 47\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 48\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 49\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 50\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 51\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 52\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 53\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 54\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 55\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 56\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 57\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 58\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 59\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 60\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 61\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 62\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 63\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 64\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 65\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 66\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 67\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 68\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 69\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 70\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 71\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 72\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 73\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 74\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 75\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 76\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 77\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 78\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 79\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 80\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 81\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 82\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 83\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 84\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 85\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 86\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 87\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 88\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 89\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 90\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 91\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 92\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 93\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 94\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 95\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 96\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 97\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 98\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 99\n"
     ]
    }
   ],
   "source": [
    "# 死循环 \n",
    "# 它可以实现for循环的指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯...\",count)\n",
    "    count = count+1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b35a81f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "猜一猜（0-100）:88\n",
      "往小猜！加油！\n",
      "猜一猜（0-100）:77\n",
      "往大的猜！\n",
      "猜一猜（0-100）:80\n",
      "往小猜！加油！\n",
      "猜一猜（0-100）:79\n",
      "往小猜！加油！\n",
      "猜一猜（0-100）:78\n",
      "你超棒！！！\n"
     ]
    }
   ],
   "source": [
    "## 小游戏: 猜数字 , 5次\n",
    "# 1. hide_card   : 0-100 ,大了，小了\n",
    "# 2. guess_digit : 50\n",
    "import getpass\n",
    "count = 0\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "\n",
    "\n",
    "while True:\n",
    "    guess_digit = int(input(\"猜一猜（0-100）:\"))\n",
    "    # 对比：\n",
    "    if hide_card == guess_digit:\n",
    "        print(\"你超棒！！！\")\n",
    "    elif guess_digit>hide_card:\n",
    "        print(\"往小猜！加油！\")\n",
    "    else:\n",
    "        print(\"往大的猜！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e536644",
   "metadata": {},
   "source": [
    "# 课后练习：\n",
    "\n",
    "> 1.列表的切片和方法的使用\n",
    "\n",
    ">>a.课本P67 练习\n",
    "\n",
    ">>b.课本P81 练习\n",
    "\n",
    "> 2.P89:列表，我们已经知道什么（列表总结）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "280254f8",
   "metadata": {},
   "source": [
    "* P67练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "569144c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "30318aa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4e6a70f",
   "metadata": {},
   "source": [
    "* P81练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "284701ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f06b5fd",
   "metadata": {},
   "source": [
    "* 标注：列表切片是非破坏性的，因为从一个现有列表中抽取对象不会改变原来的列表，原数据仍保持不变。\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b963571",
   "metadata": {},
   "source": [
    "* P89列表：更新我们已经知道些什么"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6992e1b",
   "metadata": {},
   "source": [
    "|  列表的方法 |  Description  |     使用方法    |      备注     |\n",
    "| ----------  | ------------------| ------------------- | ----------------- |\n",
    "|  append  |   Append object to the end of the list.  | list.append(object) | 注意：增加在末尾！|\n",
    "|  clear  |    Remove all items from list.| list.clear(self)| 注意：将元素清空|\n",
    "|  copy   |   Return a shallow copy of the list.   | list.copy(self)  |注意：不等价于 = |\n",
    "|  count   |  Return number of occurrences of value. | list.count(self,value)  | 注意：返回的是某个元素在列表里面的个数 |\n",
    "|  extend  |  Extend list by appending elements from the iterable.  | list.extend(self, iterable) | 注意：在list的末尾添加元素 |\n",
    "|  index   | Return first index of value.  | list.index(self, value)  | 注意：返回的是元素在列表中的第一个位置 |\n",
    "|  insert  | Insert object before index.   | list.insert(self, index, object)   |注意： 向指定的地方添加元素 |\n",
    "|  pop   |  Remove and return item at index (default last). | list.pop(self, index=-1)  |注意：删除列表尾部的元素,返回删除的元素 |\n",
    "|  remove |  Remove first occurrence of value. | list.remove(self, value) | 注意：删除的是第一次出现的元素，如果元素不存在会报错  |\n",
    "|  reverse  | Reverse *IN PLACE*.    | list.reverse(self) | 注意：将列表进行翻转  |\n",
    "|  sort    | Sort the list in ascending order and return None. |list.sort(self)|注意：对列表进行排序，反向标志可以设置为按降序排序 |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69c4b1e0",
   "metadata": {},
   "source": [
    "|  列表 | 总结  | \n",
    "| ----------  | ------------------|\n",
    "|1.|列表认识中括号记法，可以用中括号来记法从任何列表选择单个对象。|\n",
    "|2.|与很多其他编程语言类似，Python从0开始计数，所以列表中的第一个对象位于索引位置0，第2个对象处于索引位置1。|\n",
    "|3.|Python允许从任意两端索引列表。使用-1会选择列表中的最后一项，-2会选择倒数第2个对象。|\n",
    "|4.|列表支持在中括号记法中指定开始、结束和步长值，可以提供列表的切片（或片段）。|\n",
    "|5.|只要需要存储任何相关对象的一个集合，列表就是很好的选择。|\n",
    "|6.|如果有一组类似的对象，需要把它们存储在一个数据结构中，列表就是理想的选择。|\n",
    "|7.|列表很擅长存储相关字母的集合，如vowels列表。如果数据是一个数字集合，列表也是很好的选择。|\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04f3a32b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
